import Vue from 'vue'
import Router from 'vue-router'
import Welcome from '@/components/Welcome.vue'

Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/home',
      name: 'Home',
      meta: { requireAuth: true },
      redirect: '/welcome',
      component: (resolve) => require(['@/components/Home'], resolve),
      children: [
        {
          path: '',
          name: 'welcome',
          component: (resolve) => require(['@/components/Welcome'], resolve),
        },
        {
          path: '/welcome',
          name: 'welcome',
          component: (resolve) => require(['@/components/Welcome'], resolve),
        },
        {
          path: '/user',
          name: 'user',
          component: (resolve) => require(['@/components/User'], resolve)
        },
        {
          path: '/housePropertyView',
          name: 'houseProperty',
          component: () => import('../views/houseProperty/housePropertyView.vue')
        },
        {
          path: '/ConsumablesDistribute',//易耗品分发
          name: 'ConsumablesDistribute',//易耗品分发
          component: (resolve) => require(['@/views/Consumables/ConsumablesDistribute'], resolve),
        },
        {
          path: '/ConsumablesUnprocessed',//查看未处理申请
          name: 'ConsumablesUnprocessed',//
          component: (resolve) => require(['@/views/Consumables/ConsumablesUnprocessed'], resolve),
        },
        {
          path: '/ConsumvlesWriteoff',//易耗品核销
          name: 'ConsumvlesWriteoff',
          component: (resolve) => require(['@/views/Consumables/ConsumvlesWriteoff'], resolve)
        },
        {
          path: '/ConsumablesStorage',//易耗品入库
          name: 'ConsumablesStorage',
          component: (resolve) => require(['@/views/Consumables/ConsumablesStorage'], resolve)
        },
        {
          path: '/userManage',//主页面
          name: 'userManage',//主页面
          component: (resolve) => require(['@/views/SystemMange/userManagement'], resolve),//主页面路径
        },
        {
          path: '/userConfig',//主页面
          name: 'userConfig',//主页面
          component: (resolve) => require(['@/views/SystemMange/userConfig'], resolve),//主页面路径
        },
        {
          path: '/structureManage',//主页面
          name: 'structureManage',//主页面
          component: (resolve) => require(['@/views/SystemMange/structureManagement'], resolve),//主页面路径
        },
        {
          path: '/viewsScrap',//主页面
          name: 'viewsScrap',//主页面
          component: (resolve) => require(['@/views/equipment/viewsScrap.vue'], resolve),//主页面路径
        },
        {
          path: '/viewsRepairs',//主页面
          name: 'viewsRepairs',//主页面
          component: (resolve) => require(['@/views/equipment/viewsRepairs.vue'], resolve),//主页面路径
        },
        {
          path: '/viewsLose',//主页面
          name: 'viewsLose',//主页面
          component: (resolve) => require(['@/views/equipment/viewsLose.vue'], resolve),//主页面路径
        },
        {
          path: '/viewsLease',//主页面
          name: 'viewsLease',//主页面
          component: (resolve) => require(['@/views/equipment/viewsLease.vue'], resolve),//主页面路径
        },
        {
          path: '/viewsFacility',//主页面
          name: 'viewsFacility',//主页面
          component: (resolve) => require(['@/views/equipment/viewsFacility.vue'], resolve),//主页面路径
        },
        {
          path: '/ApprovalOfBte',
          name: 'ApprovalOfBte',
          component: (resolve) => require(['@/views/Approval/ApprovalOfBte.vue'], resolve)
        },
        {
          path: '/ApprovalOfConsumable',
          name: 'ApprovalOfConsumable',
          component: (resolve) => require(['@/views/Approval/ApprovalOfConsumable.vue'], resolve)
          // ApplicationForTeaching
        },
        {
          path: '/teachingView',
          name: 'teachingView',
          component: (resolve) => require(['@/views/Approval/ApplicationForTeaching.vue'], resolve),
          // ApplicationForTeaching
          
        },
        {
          path: '/borrow',
          name: 'borrow',
          component: (resolve) => require(['@/views/Application/borrow.vue'], resolve),
        },
        {
          path: '/ClaimView',
          name: 'ClaimView',
          component: (resolve) => require(['@/views/Application/ClaimView.vue'], resolve)
        },
        {
          path: '/landedView',
          name: 'landed',
          component: () => import('../views/landed/landedView.vue')
        },
        {
          path: '/housePropertyView',
          name: 'houseProperty',
          component: () => import('../views/houseProperty/housePropertyView.vue')
        },
        {
          path: '/housePropertyReformView',
          name: 'housePropertyReform',
          component: () => import('../views/houseProperty/housePropertyReformView.vue')
        },
        {
          path: '/housePropertyMaintenanceView',
          name: 'housePropertyMaintenance',
          component: () => import('../views/houseProperty/housePropertyMaintenanceView.vue')
        },
        {
          path: '/landedMaintenanceView',
          name: 'landedMaintenance',
          component: () => import('../views/landed/landedMaintenanceView.vue')
        },
        {
          path: '/inventory',
          name: 'inventory',
          component: (resolve) => require(['@/views/Statistics/inventory.vue'], resolve)
        },
        {
          path: '/ledger',
          name: 'ledger',
          component: (resolve) => require(['@/views/Statistics/ledger.vue'], resolve)
        },
        {
          path: '/check',
          name: 'check',
          component: (resolve) => require(['@/views/Statistics/check.vue'], resolve)
        },
        {
          path: '/pan_start',
          name: 'pan_start',
          component: (resolve) => require(['@/views/Statistics/pan_start.vue'], resolve)
        },
        {
          path: '/detail_pan',
          name: 'detail_pan',
          component: (resolve) => require(['@/views/Statistics/detail_pan.vue'], resolve)
        },
        {
          path: '/ApprovalView',//审批流程设置
          name: 'ApprovalView',
          component: (resolve) => require(['@/views/Infrastructure/ApprovalView.vue'], resolve)
        },

        {
          path: '/AssetClassView',//资产存放地点
          name: 'AssetClassView',
          component: (resolve) => require(['@/views/Infrastructure/AssetClassView.vue'], resolve)
        },

        {
          path: '/DepositView',//资产分类设置
          name: 'DepositView',
          component: (resolve) => require(['@/views/Infrastructure/DepositView.vue'], resolve)
        },
        {
          path: '/Lendandreturn',//借出和归还
          name: 'Lendandreturn',
          component: (resolve) => require(['@/views/Devicemanagement/Lendandreturn.vue'], resolve),
          children: [
           
          ]
        },
        {
          path: '/Notprocessed',
          name: 'Notprocessed',
          component: () => import('../views/Devicemanagement/Notprocessed.vue')
        },
        {
          path: '/facilityLossView',
          name: 'facilityLoss',
          component: () => import('../views/facility/facilityLossView.vue')

        }
      ]
    },
    {
      path: '/',
      name: 'index',
      component: (resolve) => require(['@/components/Login'], resolve)
    },
    {
      path: '/login',
      name: 'Login',
      component: (resolve) => require(['@/components/Login'], resolve)
    }
    // {
    //   path: '/structureManage',
    //   name: 'structureManage',
    //   component: (resolve) => require(['@/views/SystemMange/userManagement.vue'], resolve)
    // }
    // {
    //   path:'/*',
    //   name: '404',
    //   component: (resolve)=> require(['@/components/Page404'],resolve)
    // },
  ]
})

router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next();
  //获取token
  const nameStr = window.localStorage.getItem('name')
  if (!nameStr) {
    // this.$message({
    //   message: '请登录后访问',
    //   type: 'warning'
    // });
    return next('/login')
  }
  next()
})


export default router
